package org.cnsoft.player.service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.cnsoft.framework.beans.common.RESTResultBean;
import org.cnsoft.framework.beans.user.UserBean;
import org.cnsoft.framework.utils.EmptyHelper;
import org.cnsoft.framework.weixin.ISWeixinLoginService;
import org.cnsoft.framework.weixin.bean.WxCallBackParamBean;
import org.springframework.stereotype.Service;

/**
 * 用户登录
 * 
 * @author ZmSoft
 * @version 0.1.0 2018/3/1
 * @since 0.1.0 2018/3/1
 * @see ApiManagerLoginController
 */
@Service("ISWeixinLoginService") // 替换系统登录接口
//@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class WeixinPlayerLoginService extends PlayerLoginService implements ISWeixinLoginService {

	/**
	 * 微信登录
	 * @see <ISWxPlayerInfo>
	 */
	public RESTResultBean<UserBean> doWeixinLogin(HttpServletRequest request, HttpServletResponse response, WxCallBackParamBean wxLoginer) throws Exception {
		logger.debug("UserBean==>>>" + wxLoginer);
		RESTResultBean<UserBean> result = new RESTResultBean<UserBean>();
		// 根据OpenID查找用户
		if (EmptyHelper.isEmpty(wxLoginer.getOpenid())) {
			//非法用户，异常出去
			result.setCode(1);
			result.setMsg("非法操作，请重新打开。");
			return result;
		}

		//检查用户是否存在
		UserBean curUser = myPlayerCheckService.checkUser(wxLoginer,true);
		result.setData(curUser);
		
		return result;
	}

}
